package com.bytz.modules.cms.reseller.job;

import cn.hutool.core.bean.BeanUtil;
import com.bytz.common.system.vo.LoginUser;
import com.bytz.common.util.SecurityUtils;
import com.bytz.modules.cms.reseller.service.IAdminEndUserService;
import com.bytz.modules.system.service.ISysUserService;
import com.bytz.modules.system.vo.SysUserVo;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@DisallowConcurrentExecution
public class SyncEndUserChineseNameJob implements Job {

    @Autowired
    private IAdminEndUserService endUserService;

    @Autowired
    ISysUserService sysUserService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {

        SysUserVo syscall = sysUserService.getUserByName("syscall");
        SecurityUtils.setLoginUser(BeanUtil.copyProperties(syscall, LoginUser.class));
        try {
            endUserService.syncChineseName();
        } catch (Exception e) {
            log.error("endUser同步失败", e);
        }
        SecurityUtils.setLoginUser(null);
    }
}
